﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

using WeChatDemo.Models;
using WeChatDemo.Models.DTO;
using WeChatDemo.Utils;

namespace WeChatDemo.DataProvider
{
    public class DAOUser : DAOBase
    {
        private static string tableName = "User";

        public static IEnumerable<DTOUser> GetAllList()
        {
            IEnumerable<DTOUser> _list = ReaderToList<DTOUser>("", "v_UserDetails");

            return _list;
        }

        public static IEnumerable<DTOUser> GetList(string queryExpression)
        {
            IEnumerable<DTOUser> _list = ReaderToList<DTOUser>(queryExpression, "v_UserDetails");

            return _list;
        }

        public static bool Add(User model)
        {
            bool flag = false;

            string _sqlString = $"INSERT INTO [User](OpenID, NickName, HeadImgUrl) VALUES('{model.OpenID}','{model.NickName}', '{model.HeadImgUrl}')";

            flag = SqlHelper.ExecuteNonQuery(_connectionString, CommandType.Text, _sqlString) == 0 ? false : true;

            return flag;
        }
    }
}